package HomeWork4;

public class SellRunnable implements Runnable{
    private Ticket ticket;
    private int num=1;

    public void set(Ticket ticket) {
        this.ticket=ticket;
    }
    public void set(int num){
        this.num = num;
    }
    public void set(Ticket ticket,int num){
        this.ticket=ticket;
        this.num = num;
    }



    @Override
    public void run() {

        Boolean flag=true;
        while (flag) {
            try {
                Thread.sleep(100);
                int i = ticket.sellTicket(num);
                if (i<=0){
                    break;
                }
                System.out.println(Thread.currentThread().getId() + "售完还剩" + i + "张票");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
}
